

PM_FUNC_NORM_ATTRIB LevelFromXP( Int:iXPAmount, Int:iType )
{
	pokemod_funcstart_debug( "LevelFromXP" );

	new Int:iStartLevel;
	while ( iXPAmount > LevelToXP( iStartLevel + 10, iType ) )
	{
		iStartLevel += 10;
	}

	new Int:iLevel = iStartLevel;
	while ( iXPAmount >= LevelToXP( iLevel, iType ) )
	{
		iLevel++;
	}

	pokemod_funcend_debug( "LevelFromXP" );

	return iLevel;
}

PM_FUNC_NORM_ATTRIB LevelToXP( Int:iLevel, Int:iType )
{
	if ( iLevel < 1 )
		return 0;

	pokemod_funcstart_debug( "LevelToXP" );

	new Int:iXP;

	switch( iType )
	{
		case 1:
		{
			iXP = power( iLevel, 3 );
		}
		case 2:
		{
			if ( iLevel <= 50 )
			{
				iXP = floatround( ( power( iLevel, 3 ) * ( 100 - iLevel ) ) / 50.0 );
			}
			else if ( iLevel <= 68 )
			{
				iXP = floatround( ( power( iLevel, 3 ) * ( 150 - iLevel ) ) / 100.0 );
			}
			else if ( iLevel <= 98 )
			{
				switch( iLevel % 3 )
				{
					case 0:
					{
						iXP = floatround( power( iLevel, 3 ) * ( 1.274 - ( iLevel / 150.0 ) - 0.000 ) );
					}
					case 1:
					{
						iXP = floatround( power( iLevel, 3 ) * ( 1.274 - ( iLevel / 150.0 ) - 0.008 ) );
					}
					case 2:
					{
						iXP = floatround( power( iLevel, 3 ) * ( 1.274 - ( iLevel / 150.0 ) - 0.014 ) );
					}
				}
			}
			else if ( iLevel < 160 )
			{
				iXP = floatround( ( power( iLevel, 3 ) * ( 160 - iLevel ) ) / 100.0 );
			}
			else
			{
				iXP = power( iLevel, 3 ) / 100;
			}
		}
		case 3:
		{
			if ( iLevel <= 15 )
			{
				iXP = floatround( ( power( iLevel, 3 ) * ( 24 + ( ( iLevel + 1 ) / 3.0 ) ) ) / 50.0 );
			}
			else if ( iLevel <= 35 )
			{
				iXP = floatround( ( power( iLevel, 3 ) * ( ( iLevel + 14 ) / 50.0 ) ) / 50.0 );
			}
			else
			{
				iXP = floatround( ( power( iLevel, 3 ) * ( 32 + ( iLevel / 2.0 ) ) ) / 50.0 );
			}
		}
		case 4:
		{
			iXP = floatround( ( ( 6 * power( iLevel, 3 ) ) / 5.0 ) - ( 15 * power( iLevel, 2 ) ) + ( 100 * iLevel ) - 140 );
		}
		case 5:
		{
			iXP = ( 4 * power( iLevel, 3 ) ) / 5;
		}
		case 6:
		{
			iXP = ( 5 * power( iLevel, 3 ) ) / 4;
		}
		default:
		{
			pokemod_debug( "LevelToXP with invalid XP type %d", iType );
		}
	}

	pokemod_funcend_debug( "LevelToXP" );

	return iXP;
}




